﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;

namespace 点击
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll", EntryPoint = "FindWindow")]
        private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);

        [DllImport("user32.dll", EntryPoint = "FindWindowEx")]
        private extern static IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

        [DllImport("user32.dll", EntryPoint = "SendMessageA")]
        private static extern int SendMessage(IntPtr hwnd, uint wMsg, int wParam, int lParam);

        private const int BM_CLICK = 0xF5;
        
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
          
            Task task = new Task(() =>
            {
                while (true)
                {
                    //  Skype for Business - 选项  00090B58  00002025A  WindowsForms10.Window.8.app.0.28bc8c8_r9_ad1
                    IntPtr maindHwnd = FindWindow("#32770", null);//主窗口标题
                    if (maindHwnd != IntPtr.Zero)
                    {
                        IntPtr childHwnd = FindWindowEx(maindHwnd, IntPtr.Zero,  "Button", "确定");//按钮控件标题
                        if (childHwnd != IntPtr.Zero)
                        {
                            SendMessage(childHwnd, BM_CLICK, 0, 0);
                        }
                    }
                }
            });

            task.Start();
        
        }

        

          

    }
}
